import os

from flask import render_template
from flask_script import Manager
from flask_migrate import MigrateCommand

from main import create_app
from main.settings import envs

env = os.environ.get('FLASK_ENV') or 'default'
app = create_app(envs.get(env))

manage = Manager(app)
manage.add_command('db', MigrateCommand)


@app.errorhandler(404)  # 自定义错误页面
def page_not_found(e):
    return render_template('404.html'), 404


@app.errorhandler(403)  # 自定义错误页面
def page_forbidden(e):
    return render_template('403.html'), 403


if __name__ == '__main__':
    manage.run()
